package org.vaadinpa.logic;

import java.util.Date;

public class CountdownThread extends Thread {

	private long timeToCountTo;

	public CountdownThread(long millisToCount) {
		timeToCountTo = System.currentTimeMillis() + millisToCount;
	}

	@Override
	public void run() {
		setName("VaadinPA tick countown thread");

		try {

			while (true) {
				sleep(200);

				if (System.currentTimeMillis() > timeToCountTo) {
					Ticker.startTicks();
					break;
				}

			}

		} catch (InterruptedException CONTINUE) {
			// let thread die
		}

	}

	public Date getStartTime() {
		return new Date(timeToCountTo);
	}
}
